
var UserList = new Pearlsen.BaseList({
	gridId:'userGrid',
	advSearchId:'advSearchWin',
	module:'用户',
	modulePath:'/pages/sysmgr/user/',
	moduleName:'User',
	idProperty:'USER_ID',
	nameProperty:'USER_NAME',
	dataSetHandler:'SysUserDataSetHandler',
	queryHandler:'SysUserLoadHandler',

	statusRender:function(value){
        var val = "";
        switch (value) {
            case "1":
                val = "<span style='color:green;'>启用</span>";
                break;
            case "0":
                val = "<span style='color:red;'>停用</span>";
                break;
        }
        return val;
	},
	assignRole:function(){
		var me = this;
		var record = me.getSelectedOne();
		if( !record ) {
			Pearlsen.Utils.showInfoMsg('请先选中一条记录.');
			return ;
		}else{
			var tabId = this.createTabId("assignRole",record.data[this.idProperty]);
			me.currentWin = Pearlsen.Utils.openWindow("tabId","分配角色",me.modulePath+"/assignRole.jsp",true,500,300);
		}
	},
	_delOne:function(){
     	var me = this;
		var record = this.getSelectedOne();
     	if( Ext.isEmpty(record) ){
     		return ;
     	}
        Ext.MessageBox.confirm('删除提示', '确定要删除【'+record.data[this.nameProperty]+'】吗?',function(btn){
        	if(btn=='yes'){
        		if( !me.dataSetHandler ){
        			throw new Error("未设置没有指定dataSetHandler");
        		}
         	 	var ds=new DataSet(me.dataSetHandler,me.moduleName+"_dataset");
         	 	ds.setHandlerMethod(me.deleteMethod);
         	 	ds.newRecord();
  				ds.setValue("objId",record.data[me.idProperty]);
     			ds.execute(function(result){
     				if( result.success ){
     					me.refreshGrid();
     				}else{
     					Pearlsen.Utils.showErrorMsg("出错了,原因:"+result.message);
     				}
     			});
         	 }
		});
	},
	/***
	 * 删除所有选中的数据
	 */
	_delAll:function(){
     	var me = this;
		var records = this.getSelected();
     	if( Ext.isEmpty(records) ){
     		return ;
     	}
        Ext.MessageBox.confirm('删除提示', '确定要删除所有选中的记录吗?',function(btn){
        	if(btn=='yes'){
        		if( !me.dataSetHandler ){
        			throw new Error("未设置没有指定dataSetHandler");
        		}
        		var ds=new DataSet(me.dataSetHandler,me.moduleName+"_dataset");
				for (var i = 0; i < records.length; i++) {
					ds.newRecord();
  					ds.setValue("objId",records[i].data[me.idProperty]);
				}
         	 	ds.setHandlerMethod(me.deleteAllMethod);
     			ds.execute(function(result){
     				if( result.success ){
     					me.refreshGrid();
     				}else{
     					Pearlsen.Utils.showErrorMsg("出错了,原因:"+result.message);
     				}
     			});
         	 }
		});		
	},
	resetPwd:function(){
		var me = this;
		var records = this.getSelected();
     	if( Ext.isEmpty(records)){
     		Pearlsen.Utils.showInfoMsg('请先选中一条记录.');
     		return ;
     	}
		var form = Ext.create('Ext.form.Panel', {
        layout: 'absolute',
        url: 'save-form.php',
        defaultType: 'textfield',
        border: false,

        items: [{
            fieldLabel: '新密码',
            fieldWidth: 60,
            msgTarget: 'side',
            inputType: 'password',
            allowBlank: false,
            x: 5,
            y: 5,
            name: 'password1',
            id: 'password1',
            anchor: '-5'  // anchor width by percentage
        }, {
            fieldLabel: '确认密码',
            fieldWidth: 60,
         	inputType: 'password',
         	allowBlank: false,
            x: 5,
            y: 35,
            name: 'password2',
            id: 'password2',
            anchor: '-5'  // anchor width by percentage
        }]
    });
		var pwdWin = Ext.create('widget.window',{
				title:"重置密码",
				width: 300,
                height: 200,
                layout:'fit',
                items:form,
                plain:true,
                buttons:[
                	{text:'确定',handler:function(){
                			if(!form.getForm().isValid()){
                				return;
                			}
                			var pass1 =Ext.getCmp("password1").getValue();
                			var pass2 =Ext.getCmp("password2").getValue();
                			if(pass1!=pass2){
                				Pearlsen.Utils.showWarnMsg("输入密码不一致");
                				return ;
                			}
                			var ds=new DataSet(me.dataSetHandler,me.moduleName+"_dataset");
                			ds.addCondition("password",pass2);
							for (var i = 0; i < records.length; i++) {
								ds.newRecord();
			  					ds.setValue("objId",records[i].data[me.idProperty]);
							}
			         	 	ds.setHandlerMethod("resetPwd");
			     			ds.execute(function(result){
			     				if( result.success ){
			     					Pearlsen.Utils.showSuccessMsg('密码重置成功!');
			     				}else{
			     					Pearlsen.Utils.showErrorMsg("出错了,原因:"+result.message);
			     				}
			     			});
                			
							pwdWin.hide();
                	}},
                	{text:'取消',handler:function(){
                		pwdWin.hide();
                	}}
                ]
			});
		pwdWin.show();
	}
	
	
	
});

